/**
 * Copyright 2009-2011 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.myjung.model;

import net.myjung.model.annotation.MdlAttribute;
import net.myjung.model.annotation.MdlText;

/**
 * @author Steve M. Jung
 */
@SuppressWarnings("serial")
public class Property extends BaseObject {
	@MdlAttribute
	private String name;
	@MdlText
	private String value;
	public Property(String name, String value) {
		this.name = name;
		this.value = value;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public static Property[] add(Property[] objs, Property obj) {
		if (obj == null)
			return objs;
		int size = 0;
		if (objs != null)
			size = objs.length;
		Property[] newObjs = new Property[size + 1];
		int i;
		for (i = 0; i < size; i++)
			newObjs[i] = objs[i];
		newObjs[i] = obj;
		return newObjs;
	}
	public static Property[] remove(Property[] objs, Property obj) {
		if (obj == null)
			return objs;
		int size = 0;
		if (objs != null)
			size = objs.length;
		if (size == 0)
			return objs;
		Property[] newObjs = new Property[size - 1];
		int i;
		int j = 0;
		for (i = 0; i < size; i++) {
			if (objs[i].equals(obj))
				continue;
			newObjs[j++] = objs[i];
		}
		return newObjs;
	}
	public static Property[] left(Property[] objs, Property obj) {
		if (objs == null || objs.length == 0 || obj == null)
			return objs;
		int idx = -1;
		for (int i = 0; i < objs.length; i++) {
			if (!objs[i].equals(obj))
				continue;
			idx = i;
			break;
		}
		if (idx < 1)
			return objs;
		Property[] newObjs = new Property[objs.length];
		for (int i = 0; i < objs.length; i++) {
			if (i == idx) {
				newObjs[i] = objs[idx - 1];
				continue;
			} else if (i == idx - 1) {
				newObjs[i] = objs[idx];
				continue;
			}
			newObjs[i] = objs[i];
		}
		return newObjs;
	}
	public static Property[] right(Property[] objs, Property obj) {
		if (objs == null || objs.length == 0 || obj == null)
			return objs;
		int idx = -1;
		for (int i = 0; i < objs.length; i++) {
			if (!objs[i].equals(obj))
				continue;
			idx = i;
			break;
		}
		if (idx == -1 || idx + 1 == objs.length)
			return objs;
		Property[] newObjs = new Property[objs.length];
		for (int i = 0; i < objs.length; i++) {
			if (i == idx) {
				newObjs[i] = objs[idx + 1];
				continue;
			} else if (i == idx + 1) {
				newObjs[i] = objs[idx];
				continue;
			}
			newObjs[i] = objs[i];
		}
		return newObjs;
	}
}
